package com.koron.configure.safetcf.service.imp;


import com.koron.common.core.config.ThreadLocalContext;
import com.koron.common.core.util.CodeTools;
import com.koron.common.core.util.StringUtils;
import com.koron.configure.safetcf.bean.SafetCFyBean;
import com.koron.configure.safetcf.mapper.SafetyCFBeanMapper;
import com.koron.configure.safetcf.service.SafetCFService;
import lombok.extern.slf4j.Slf4j;
import org.koron.ebs.mybatis.SessionFactory;
import org.koron.ebs.mybatis.TaskAnnotation;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class SafetCFImpService implements SafetCFService {

    private String getCurrDs() {
        return ThreadLocalContext.get().getCurrDs();
    }

    @Override
    @TaskAnnotation("savePrio")
    public String savePrio(SessionFactory factory, SafetCFyBean bean) {
        SafetyCFBeanMapper mapper = factory.getMapper(SafetyCFBeanMapper.class);
        if (StringUtils.isEmpty(bean.getId())) {
            String id = CodeTools.getCode32();
            bean.setId(id);
            mapper.insertSelective(bean);
        } else {
            mapper.updateByPrimaryKeySelective(bean);
        }
        return bean.getId();
    }


}
